﻿using System;
using PaperWorld.DTO;
using PaperWorld.IRepository;
using PaperWorld.IService;

namespace PaperWorld.Service
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public class UserService : IUserService
    {
        private IUserRepository userRepository;

        public UserService(IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }

        /// <summary>
        /// 用户登录服务
        /// </summary>
        /// <param name="request">用户登录请求DTO对象</param>
        /// <returns>用户登录响应对象</returns>
        public UserLoginResponse Login(UserLoginRequest request)
        {
            var result = userRepository.GetModel(t => t.Username == request.UserName && t.Password == request.Password);
            if (result == null || result.ID == Guid.Empty)
            {
                return new UserLoginResponse
                {
                    State = false,
                    Message = "用户名或密码错误"
                };
            }
            else
            {
                return new UserLoginResponse
                {
                    State = true,
                    Message = "登录成功"
                };

            }
        }
    }
}
